Testing Backbone.js by Roemer Ryan
Author:Roemer, Ryan
Language: eng
Format: epub
Publisher: Packt Publishing
Anonymous spies
Spies can be created as anonymous standalone functions, which are often used to test event logic in Backbone.js applications. For example, we create a Backbone.js event object and an anonymous Sinon.JS spy in the following code. The spy listens to the foo event, which we trigger. Then, we can inspect the spy and assert that the spy was called once and passed 42 as a parameter:
it("calls anonymous spy on event", function () { var eventer = _.extend({}, Backbone.Events), spy = sinon.spy(); // Set up the spy. eventer.on("foo", spy); expect(spy.called).to.be.false; // Fire event. eventer.trigger("foo", 42); // Check number of calls. expect(spy.calledOnce).to.be.true; expect(spy.callCount).to.equal(1); // Check calling arguments. expect(spy.firstCall.args[0]).to.equal(42); expect(spy.calledWith(42)).to.be.true; });
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Grails in Action by Glen Smith Peter Ledbrook(9163)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(8808)
Azure Containers Explained by Wesley Haakman & Richard Hooper(7444)
Configuring Windows Server Hybrid Advanced Services Exam Ref AZ-801 by Chris Gill(7433)
Kotlin in Action by Dmitry Jemerov(7263)
Running Windows Containers on AWS by Marcio Morales(6984)
Microsoft 365 Identity and Services Exam Guide MS-100 by Aaron Guilmette(5402)
Microsoft Cybersecurity Architect Exam Ref SC-100 by Dwayne Natwick(5212)
Combating Crime on the Dark Web by Nearchos Nearchou(4981)
The Ruby Workshop by Akshat Paul Peter Philips Dániel Szabó and Cheyne Wallace(4670)
Management Strategies for the Cloud Revolution: How Cloud Computing Is Transforming Business and Why You Can't Afford to Be Left Behind by Charles Babcock(4527)
Python for Security and Networking - Third Edition by José Manuel Ortega(4233)
The Age of Surveillance Capitalism by Shoshana Zuboff(4209)
Learn Wireshark by Lisa Bock(4119)
The Ultimate Docker Container Book by Schenker Gabriel N.;(3888)
Learn Windows PowerShell in a Month of Lunches by Don Jones(3681)
DevSecOps in Practice with VMware Tanzu by Parth Pandit & Robert Hardt(3568)
Windows Ransomware Detection and Protection by Marius Sandbu(3541)
Blockchain Basics by Daniel Drescher(3507)